# -*- coding: utf-8 -*-
# @Time    : 2019/11/18
# @Author  : CHENlj
# @File    : Yaml.py
import yaml, os


def read_yaml(file_name):
    """
    读取yaml文件
    :param file_name:
    :return:
    """
    base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    data_dir = os.path.join(base_dir, 'Data')
    file_path = os.path.join(data_dir, file_name)

    with open(file_path, "r") as f:
        return yaml.load(f, Loader=yaml.FullLoader)


def write_yaml(file_name, data):
    """
    写入yaml文件
    :param file_name:
    :param data:
    :return:
    """
    base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    data_dir = os.path.join(base_dir, 'Data')
    file_path = os.path.join(data_dir, file_name)

    with open(file_path, 'w') as f:
        yaml.dump(data, f, encoding='utf-8', allow_unicode=True)


if __name__ == '__main__':
    # ret = read_yaml('add_user.yml')
    # print(ret)
    data = {'Search_Data': {
        'search_test_002': {'expect': {'value': '你好'}, 'value': '你好'},
        'search_test_001': {'expect': [4, 5, 6], 'value': 456}}}

    write_yaml('test.yml', data)